<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{&SITE_TITLE}</title>
  <link href="__PUBLIC__/admin/css/layout.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="__PUBLIC__/js/jquery.js" ></script>

    <script type="text/javascript">
    var widgetField = new Array();
    <php>foreach($fields as $key=>$value){</php>
    widgetField['{$key}'] = new Array();
    <php>foreach($value as $sokey=>$sovalue){</php>
    widgetField['{$key}'][{$sokey}] = new Array();
    widgetField['{$key}'][{$sokey}]['id'] = {$sovalue['id']};
    widgetField['{$key}'][{$sokey}]['label'] = '{$sovalue['label']}'; 
    <php>}</php>
    <php>}</php>

    var selected_widget = {$poster.extraField|sizeOf};
    var array = new Array();
    <php>foreach($widget as $key=>$value){</php>
        array[{$value['id']}] = '{$value['field']}';
    <php>}</php>
    $(function(){
        if(selected_widget == {$fields|sizeOf}){
            $('#addWidget').attr('disabled','disabled');
        }
    })
    function addWidget(_this){
        var val = $('#widget').val();
        if(val == 0){
            return;
        }
        var label = $('select option[value='+val+']').text();
        var field = array[val];
        var option = "";
        for(var i=0;i<widgetField[field].length;i++){
            var field_id = widgetField[field][i]['id'];
            var field_label = widgetField[field][i]['label'];
            if(field_id != val){
            	var del_option = '<option value="'+field_id+'">'+field_label+'</option>';
            }else{
            	var del_option = '<option value="'+field_id+'" selected>'+field_label+'</option>';
            }
            
        	option += del_option;
            $('select option[value='+field_id+']').remove();
        }
        
      
        var div = '<div id="widget'+val+'">\
        <select name="widget[]">'+option+'</select>\
        <a href="javascript:void(0)" rel="'+field+'" onclick="deleteWidget('+val+',this)">删除</a>\
            </div>\
            ';

        if(selected_widget == 0){
            $('#poster_widget').text("");
        }
        selected_widget ++;
            $('#poster_widget').append(div);
       if(selected_widget == {$fields|sizeOf}){
   	       $(this).attr('disabled','disabled');
       }
    }
    function deleteWidget(id,_this){
        var field = $(_this).attr('rel');
        for(var i=0;i<widgetField[field].length;i++){
            var option = '<option value="'+widgetField[field][i]['id']+'">'+widgetField[field][i]['label']+'</option>'
            $('#widget').append(option);
        }
        $('#widget'+id).remove();
        selected_widget --;
       if(selected_widget == 0){
    	   $('#poster_widget').text("未启用任何额外字段");
       }
       if(selected_widget != {$fields|sizeOf}){
    	   $('#addWidget').removeAttr('disabled');
       }
    }
    </script>
    </head>
    <body>
        <div id="container">
             <form action = "__URL__/doEditType/" method="post">
                <table class="tableborder" width="100%">
                <tbody>
                    <tr class="top">
                        <td class="border" colspan="2"></td>
                    </tr>
                    <tr>
                        <th class="header" colspan="2">招贴板分类修改</th>
                    </tr>
                    <tr class="label">
                        <th>说明</th>
                        <th>设置</th>
                    </tr>
                    <tr class="cell">
                        <td class="altbg1">
                            <b>分类名</b>
                            <br/>
                            <span class="smalltxt">填写在前台显示的招贴板大分类：如招聘，物品交换</span>
                        </td>
                            <td class="altbg2"><input name="name" class="txt" value="{$poster.name}" /></td>
                    </tr>
                    <tr class="cell">
                        <td class="altbg1">
                            <b>子分类</b>
                            <br/>
                            <span class="smalltxt">此分类信息下的小分类</span>
                        </td>
                            <td class="altbg2">
                                <select name="type">
                                <option value="0">未启用小分类</option>
                                     <volist name="smallType" id="vo">
                                        <option value="{$vo.label}" <php>if($vo['label'] == $poster['type']) echo "selected";</php>>{$vo.label}</option>
                                     </volist>
                                </select>
                            </td>
                    </tr>
                    
                    <tr class="cell">
                        <td class="altbg1">
                            <b>图标</b>
                            <br/>
                            <span class="smalltxt">分类所使用的图标。在应用的images/ico下。注意图片不要太大</span>
                        </td>
                            <td class="altbg2">
                            <select name="ico" >
                                <volist name="ico" id="vo">
                                    <option value="{$vo}" <php>if($vo === $poster['ico']) echo "selected";</php>>{$vo}</option>
                                </volist>
                            </select>
                            </td>
                    </tr>
                    <tr class="cell">
                        <td class="altbg1">
                            <b>额外字段</b>
                            <br/>
                            <span class="smalltxt">额外字段</span>
                        </td>
                            <td class="altbg2" id="poster_widget">
                                <volist name="poster.extraField" id="vo" empty="未启用任何额外字段">
                                    <div id="widget{$vo.id}">
                                        <select name="widget[]">
                                            <php>foreach($fields[$vo['field']] as $so){</php>
                                            <option value="{$so.id}"<php>if($so['id']==$vo['id']) echo "selected";</php>>{$so.label}</option>
                                            <php>}</php>
                                        </select>
                                    <a href="javascript:void(0)" rel ="{$vo.field}" onclick="deleteWidget({$vo.id},this)">删除</a>
                                    </div>
                                </volist>
                            </td>
                    </tr>
                    <tr class="cell">
                        <td class="altbg1">
                            <b>描述</b>
                            <br/>
                            <span class="smalltxt">填写对这个分类的描述。会在前台显示</span>
                        </td>
                            <td class="altbg2"><textarea name="explain" class="txt" cols="30" rows="10">{$poster.explain}</textarea></td>
                    </tr>
                    
                   
                    
                    <tr>
                        <td class="footer" colspan="2">
                         <input type="hidden" name="id" value="{$poster.id}">
                            <input type="submit" class="submit" value="提交" />
                        </td>
                    </tr>
                    </tbody>
            </table>
      </form>
      <select id="widget">
      <option value="0">无额外项</option>
        <volist name="liveField" id="vo">
               <option value="{$vo.id}">{$vo.label}</option>
        </volist>
      </select>
      <input id="addWidget" type="button" class="button" onclick="addWidget()" value="添加">
        </div>
    </body>
</html>
